package com.ms.oschina.adapter;

import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;

import com.ms.oschina.api.remote.OsChinaApi;
import com.ms.oschina.base.BaseViewHolder;
import com.ms.oschina.bean.Blog;
import com.ms.oschina.bean.Constants;
import com.ms.oschina.tagpager.NewsFragment;
import com.ms.oschina.ui.activity.NewsDetailsActivity;
import com.ms.oschina.util.UiUtils;
import com.ms.oschina.viewholder.BlogViewHolder;

public class BlogAdapter extends PageIndexListAdapter<Blog> {

	public BlogAdapter(AbsListView listView, List<Blog> list,
			boolean loadMore) {
		super(listView, list, loadMore);
	}

	@Override
	public void onNormalItemClick(AdapterView<?> parent, View view,
			int position, long id) {
		Blog blog = getListData().get(position);
		// 开启新闻详情界面
		Context context = UiUtils.getContext();
		Intent intent = new Intent(context, NewsDetailsActivity.class);
		intent.putExtra(Constants.NEWSBLOGDETAILS_ID, blog.getId());
		intent.putExtra(Constants.MARK,Constants.MARK_NEWSBLOGDETAILS);
		intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		context.startActivity(intent);
	}

	@Override
	public BaseViewHolder<Blog> getItemViewHolder() {
		return new BlogViewHolder();
	}

	@Override
	public List<Blog> getLoadMoreData() throws Exception {
		int mark = getMark();
		switch (mark) {
		case NewsFragment.BLOGS:// 博客
			return OsChinaApi.getNewsBlog(pageIndex).getBloglist();
		case NewsFragment.RECOMMEND:// 推荐
			// return OsChinaApi.getNewsHotspot(pageIndex).getList();
		default:
			return null;
		}
	}

}
